//
//  YCShopMessageViewController.m
//  lianganyuchu
//
//  Created by iMac on 17/2/23.
//  Copyright © 2017年 杭州桑缇电子商务有限公司. All rights reserved.
//

#import "YCShopMessageViewController.h"
#define YCMessage1CellIdentify @"YCMessage1TableViewCell"
#define YCMessage2CellIdentify @"YCMessage2TableViewCell"
#define YCMessage3CellIdentify @"YCMessage3TableViewCell"

@interface YCShopMessageViewController ()
{
    UITableView *m_tableView;
    ShopTable *_shopTable;
}
@end

@implementation YCShopMessageViewController
-(void)viewWillAppear:(BOOL)animated
{
    [_naviVC setNaviHidden:NO];
    [_naviVC setMainNaviVC];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"门店信息";
    self.navigationItem.leftBarButtonItem=[self tbarBackButtonWhite];
    
    [self addMianView];
    [self loadShopData];
}
-(void)loadShopData
{
    ShopIndexRequest *request = [ShopIndexRequest new];
    [apiClient hideProgress];
    [apiClient doShopIndex:request success:^(ApiResponse *data, NSString *url) {
        ShopIndexResponse *response=[[ShopIndexResponse alloc]initWithCGResponse:data];
        _shopTable=response.data;
        [m_tableView reloadData];
    }failure:^(ApiResponse *data, NSString *url){
        [self.view showHUD:data.message];
    }];
}
-(void)addMianView
{
    m_tableView=[[UITableView alloc]init];
    m_tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    m_tableView.delegate=self;
    m_tableView.dataSource=self;
    [self.view addSubview:m_tableView];
    [m_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.top.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view).offset(0);
    }];
    [m_tableView registerNib:[UINib nibWithNibName:YCMessage1CellIdentify bundle:nil] forCellReuseIdentifier:YCMessage1CellIdentify];
    [m_tableView registerNib:[UINib nibWithNibName:YCMessage2CellIdentify bundle:nil] forCellReuseIdentifier:YCMessage2CellIdentify];
    [m_tableView registerNib:[UINib nibWithNibName:YCMessage3CellIdentify bundle:nil] forCellReuseIdentifier:YCMessage3CellIdentify];
}
#pragma mark tableview datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
#pragma mark tableview delegate
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 160;
    }
    if (indexPath.section==1) {
        return 255;
    }
    return 150;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [NSString stringWithFormat:@"cell%ld%ld",(long)indexPath.section,(long)indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (nil == cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    if (indexPath.section==0) {
        YCMessage1TableViewCell *_cell = (YCMessage1TableViewCell *)[tableView dequeueReusableCellWithIdentifier:YCMessage1CellIdentify forIndexPath:indexPath];
        [_cell bindWith:_shopTable];
        cell=_cell;
    }
    if (indexPath.section==1) {
        YCMessage2TableViewCell *_cell = (YCMessage2TableViewCell *)[tableView dequeueReusableCellWithIdentifier:YCMessage2CellIdentify forIndexPath:indexPath];
        [_cell bindWith:_shopTable];
        cell=_cell;
    }
    if (indexPath.section==2) {
        YCMessage3TableViewCell *_cell = (YCMessage3TableViewCell *)[tableView dequeueReusableCellWithIdentifier:YCMessage3CellIdentify forIndexPath:indexPath];
        [_cell bindWith:_shopTable];
        cell=_cell;
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end





